const mongoose=require('mongoose');

const MessageSchema = new mongoose.Schema({
    from:{
        _id:{
            type:mongoose.Schema.ObjectId,
            ref:'User',
            required:true
        },
        name:String
    },
    to:{
        type:mongoose.Schema.ObjectId,
        ref:'User',
        required:true
    },
    action:{
        type:String,
        enum:['reply','at'],
        required:true
    },
    post:{
        _id:{
            type:mongoose.Schema.ObjectId,
            ref:'Post',
            required:true
        },
        title:String
    },
    commentId:{
        type:mongoose.Schema.ObjectId,
        ref:'Comment',
        required:true
    },
    read:{
        type:Boolean,
        default:false
    },
    time:{
        type:Date,
        required:true
    }
});

module.exports=mongoose.model('message',MessageSchema);